Ext.define('app.validator.verification', {
	extend : 'Ext.form.field.Text',
	alias : 'widget.verifycode',
	inputTyle : 'codefield',
	codeUrl : Ext.BLANK_IMAGE_URL,
	isLoader : true,
	onRender : function(ct, position) {
		this.callParent(arguments);
		this.codeEl = this.triggerWrap.createChild({
			tag : 'img',
			src : Ext.BLANK_IMAGE_URL,
			style : 'width:95px; height:20px;float:right;'
		});
		this.codeEl.on('click', this.loadCodeImg, this);
		if (this.isLoader) {
			this.loadCodeImg();
		}

		this.inputEl.setWidth(this.inputWidth - 95);
	},
	alignErrorIcon : function() {
		this.errorIcon.alignTo(this.codeEl, 'tl-tr', [ 2, 0 ]);
	},
	loadCodeImg : function() {
		var me = this;
		Ext.Ajax.request({
			url : me.codeUrl,
			method : 'POST',
			params : {
				unique : me.unique
			},
			success : function(response, opts) {
				var json = Ext.JSON.decode(response.responseText);
				if (json.rpc == 200) {
					me.codeEl.set({
						src : json.data.baseImage
					});
					me.rtn = json.data.unique;
				} else {
					Ext.Msg.alert('提示', json.msg);
				}
			}
		});
	},
	getUnique : function() {
		var me = this;
		return me.rtn;
	}
});